package Before826.AutoJudge;

import java.util.List;

public class getScore {

    // 计算并输出所有学生的得分
    public static void calculateAndPrintScores(List<String> standardAnswers, List<Student> students) {
        if (standardAnswers == null || students == null) {
            System.out.println("标准答案或学生列表为空，无法评分。");
            return;
        }

        // 计算每题的分值
        int pointsPerQuestion = 100 / standardAnswers.size();

        for (Student student : students) {
            int score = calculateScore(standardAnswers, student.getAnswer());
            student.setScore(score * pointsPerQuestion); // 设置学生的最终得分
        }
    }

    // 根据标准答案和学生答案计算得分
    private static int calculateScore(List<String> standardAnswers, List<String> studentAnswers) {
        if (studentAnswers == null || standardAnswers.size() != studentAnswers.size()) {
            return 0;
        }

        int score = 0;
        for (int i = 0; i < standardAnswers.size(); i++) {
            if (standardAnswers.get(i).equalsIgnoreCase(studentAnswers.get(i))) {
                score++;
            }
        }
        return score;
    }
}